/**
 * 页面加载时调用，检查是否是手机端，是，修改首页文字
 */
$(function () {
    const mobile_flag = isMobile(); // true为手机端，false为pc端

    if (mobile_flag) {
        // 适应手机样式，替换PC端样式
        $(".page-title").css({"font-size": "28px"});
        $(".ui-timeLine").css({"margin-left": "0", "margin-right": "10%"});
    }
});

(function ($) {
    $.fn.uiTimeLine = function () {
        var $timeLine = $(".ui-timeLine");
        var $activeLine = $(".ui-timeLine .activeLine");
        var $dots = $(".ui-timeLine .dot");
        var $cboxs = $(".ui-timeLine .item .cbox");
        return this.each(function () {
            function setActiveLineHeight() {
                let height = $(document).scrollTop() + window.screen.height;
                let j = 0;
                for (let i = 0; i < $dots.length; i++) {
                    if ($($dots[i]).offset().top < height) {
                        $($($dots[i])).addClass("active");
                        $($cboxs[i]).css({
                            "left": 0
                        });
                        j = i;
                    } else {
                        $($($dots[i])).removeClass("active")
                        $($cboxs[i]).css({
                            "left": "100vw"
                        });
                    }
                }
                $activeLine.css({
                    "height": $($dots[j]).offset().top - $timeLine.offset().top + 40 + "px"
                })
            }

            $(window).on('scroll', setActiveLineHeight);
            setActiveLineHeight();
        })
    }
})(jQuery);
